<layout name="default_layout"/>
<script type="text/javascript">

    // 视图相关代码
    allPageUrl = '__CONTROLLER__/previewAllPage/';
    allPageCodeUrl = '__CONTROLLER__/allPageCode/';
    addPageUrl = '__CONTROLLER__/addPage/';
    editPageUrl = '__CONTROLLER__/editPage/';

    // 控制器代码
    allCodeUrl = '__CONTROLLER__/controllerFunctionIndexCode/';
    addCodeUrl = '__CONTROLLER__/controllerFunctionAddCode/';
    editCodeUrl = '__CONTROLLER__/controllerFunctionEditCode/';
    deleteCodeUrl = '__CONTROLLER__/controllerFunctionDelCode/';

    // 直接生成代码
    createFlieUrl = '__CONTROLLER__/createAllFiles/'

    db_prefix = '{$db_prefix}';

    function manualCreateBtn(table) {
        isPage = $('#isPage').prop("checked");
        console.log(isPage);
        /* 列表页 */
        $.post(allPageUrl, {"table": table}, function (data) {
            $('#allPage').html(data);
        });
        $.post(allPageCodeUrl, {"table": table, "isPage": isPage}, function (data) {
            $('#allPageCode').html(data);
        });
        $.post(allCodeUrl, {"table": table, "isPage": isPage}, function (data) {
            $('#allCode').html(data);
        });
        isPage ? $('#pagination').show() : $('#pagination').hide();
        /* END-列表页 */

        /* 新建操作 */
        $.post(addPageUrl, {"table": table}, function (data) {
            $('#addPage').html(data);   // 预览
            $('#addPageCode').html(data);   // 视图代码
        });
        $.post(addCodeUrl, {"table": table}, function (data) {
            $('#addCode').html(data);   // 控制器代码
        });
        /* END-新建操作 */

        /* 编辑操作 */
        $.post(editPageUrl, {"table": table}, function (data) {
            $('#editPage').html(data);
            $('#editPageCode').html(data);
        });
        $.post(editCodeUrl, {"table": table}, function (data) {
            $('#editCode').html(data);
        });
        /* END-编辑操作 */

        /* 删除操作 */
        $.post(deleteCodeUrl, {"table": table}, function (data) {
            $('#deleteCode').html(data);
        });
        /* END-删除操作 */

    }

    jQuery(document).ready(function ($) {

        /**
         * 手动生成代码
         */
        $('#manualCreateBtn').bind("click", function () {
            table = $('#tables option:selected').val();
            console.log(table);
            if (db_prefix != '') {
                table = table.replace(db_prefix, '');
            }
            manualCreateBtn(table);
        });

        /**
         * 直接生成文件
         */
        $('#autoCreateBtn').bind("click", function () {
            moduleName = $('#moduleName option:selected').val();    // 获取模块
            isCURD = $("input[name=isCURD]").prop("checked");    // 是否生存CURD代码
            isModel = $("input[name=isModel]").prop("checked");    // 是否生存CURD代码
            extendsModuleName = $("input[name=extendsModuleName]").val();    // 获取模块
            extendsClassName = $("input[name=extendsClassName]").val();    // 获取模块
            checkedBox = $('#selectTables input:checked');  // 选择的数据表节点
            var selectTableName = [];   // 选择的数据表
            if (db_prefix != '') {
                checkedBox.each(function () {
                    selectTableName.push($(this).val().replace(db_prefix, ''));
                });
            } else {
                checkedBox.each(function () {
                    selectTableName.push($(this).val());
                });
            }

            // 发送数据
            var data = {};
            data['moduleName'] = moduleName;
            data['selectTableName'] = selectTableName;
            data['isCURD'] = isCURD;
            data['isModel'] = isModel;
            data['extendsModuleName'] = extendsModuleName;
            data['extendsClassName'] = extendsClassName;
            $.post(
                    createFlieUrl,
                    data,
                    function (data) {
                        $('#fileMsg').html(data);
                    });
            });

        /* 分页相关 */
        $('#pagination').hide();    // 隐藏分页
        /* END-分页相关 */

    });
</script>
<div class="mainbar">
<!-- Page heading -->
<div class="page-head">
    <h2 class="pull-left"><i class="icon-home"></i> 生成CRUD代码</h2>
    <div class="clearfix"></div>

</div>
<!-- Page heading ends -->


<!-- Matter -->

<div class="matter">
<div class="container">
<!-- Dashboard Graph starts -->
<div class="row">
    <div class="col-md-6">

        <div class="widget">

            <div class="widget-head">
                <div class="pull-left">直接生成文件</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <div class="padd">
                    <form class="form-horizontal">
                        <!-- 选择模块 -->
                        <div class="form-group">
                            <label class="control-label col-lg-2">选择模块</label>
                            <div class="col-lg-4">
                                <select class="form-control" id="moduleName">
                                    <volist name="moduleNameList" id="moduleName">
                                        <option value="{$moduleName}">{$moduleName}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <!-- 继承模块, 继承类对象 -->
                        <div class="form-group">
                            <label class="control-label col-lg-2">控制器继承</label>
                            <div class="col-lg-4">
                                <input type="text" name="extendsModuleName" placeholder="extendsModuleName" class="form-control">
                            </div>
                            <div class="col-lg-4">
                                <input type="text" name="extendsClassName" placeholder="extendsClassName" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <!-- 是否CURD代码 -->
                            <label class="control-label col-lg-2">是否CURD代码</label>
                            <div class="col-lg-2">
                                <input type="checkbox" name="isCURD" checked>
                            </div>
                            <!-- 是否生成model -->
                            <label class="control-label col-lg-2">是否生成model</label>
                            <div class="col-lg-2">
                                <input type="checkbox" name="isModel" checked>
                            </div>
                        </div>
                        <!-- 数据表 -->
                        <div class="form-group" id="selectTables">
                            <label class="control-label col-lg-2">数据表:</label>

                            <div class="col-lg-9">
                                <table>
                                    <tr>
                                        <volist name="tableNameList" id="table" key="key">
                                            <td>
                                                <label>
                                                    <input type="checkbox" name="table" value="{$table}"/>{$table}
                                                </label>
                                                <?php if($key%3==0)echo "</tr><tr>";?>
                                                    </td>
                                        </volist>
                                    </tr>
                                </table>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
            <!-- Widget footer -->
            <div class="widget-foot">
                <button type="button" id="autoCreateBtn" class="btn btn-primary">直接生成文件</button>
            </div>
            <!-- Widget footer end-->
            <div class="widget-foot" id="fileMsg"></div>
        </div>

    </div>


    <div class="col-md-6">
        <div class="widget">
            <div class="widget-head">
                <div class="pull-left" height="80">
                    手动生成代码
                </div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="widget-content">
                <div class="padd">
                    <div class="form quick-post">
                        <!-- Edit profile form (not working)-->
                        <div class="form-horizontal">
                            <!-- Table -->
                            <div class="form-group">
                                <label class="control-label col-lg-3">数据表:</label>
                                <div class="col-lg-9">
                                    <select class="form-control" id="tables">
                                        <volist name="tableNameList" id="table">
                                            <option value="{$table}">{$table}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                            <label class="control-label col-lg-1" for="title">生成带分页代码</label>

                            <div class="col-lg-3">
                                <input type="checkbox" id="isPage" checked/>
                            </div>
                            <!-- Buttons -->
                            <div class="form-group">
                                <!-- Buttons -->
                                <div class="col-lg-offset-2 col-lg-9">
                                    <button class="btn btn-success" id="manualCreateBtn">获取代码</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--end  paddad-->

                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">

        <!-- Widget -->
        <div class="widget">
            <!-- Widget head -->
            <div class="widget-head">
                <div class="pull-left">
                    所有列表预览(填充示例数据)
                </div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <!-- Widget content -->
            <div class="widget-content">
                <div class="padd">
                    <div id="allPage">(暂无)</div>

                    <ul class="pagination pull-right" id="pagination">
                        <li><a href="#">上一页</a></li>
                        <li><a href="#">1</a></li>
                        <li><a href="#">2</a></li>
                        <li><a href="#">3</a></li>
                        <li><a href="#">4</a></li>
                        <li><a href="#">下一页</a></li>
                    </ul>
                    <div class="clearfix"></div>
                </div>
            </div>
            <!-- Widget ends -->

        </div>
    </div>
</div>
<!-- all part1 ends -->

<div class="row">
    <div class="col-md-6">

        <div class="widget">

            <div class="widget-head">
                <div class="pull-left">所有记录列表View代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <div class="padd">
                    <textarea class="form-control" id="allPageCode" rows="12">
                    </textarea>
                </div>
            </div>
        </div>

    </div>

    <div class="col-md-6">

        <div class="widget">

            <div class="widget-head">
                <div class="pull-left">所有记录列表Controller代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <div class="padd">
                    <textarea class="form-control" id="allCode" rows="12">
                    </textarea>
                </div>
            </div>
        </div>

    </div>

</div>
<!-- all parts ends -->

<!-- Chats, File upload and Recent Comments -->
<div class="row">
    <div class="col-md-4">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">新建-效果预览</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <div class="padd">
                    <div class="form quick-post" id="addPage"></div>
                </div>
            </div>
        </div>
    </div>


    <div class="col-md-4">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">新建-View代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <textarea class="form-control" id="addPageCode" rows="12">
                </textarea>
            </div>
        </div>
    </div>


    <div class="col-md-4">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">新建-Controller代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <textarea class="form-control" id="addCode" rows="12">
                </textarea>
            </div>
        </div>
    </div>
</div>
<!--end add part-->


<div class="row">
    <div class="col-md-4">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">编辑-效果预览</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <div class="padd">
                    <div class="form quick-post" id="editPage"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">编辑View代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <textarea class="form-control" id="editPageCode" rows="12">
                </textarea>
            </div>
        </div>
    </div>


    <div class="col-md-4">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">编辑-Controller代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <textarea class="form-control" id="editCode" rows="12">
                </textarea>
            </div>
        </div>
    </div>
</div>
<!--end edit part-->


<div class="row">
    <div class="col-md-6">
        <div class="widget">
            <!-- Widget title -->
            <div class="widget-head">
                <div class="pull-left">删除-Controller代码</div>
                <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>

            <div class="widget-content">
                <textarea class="form-control" id="deleteCode" rows="12">
                </textarea>
            </div>
        </div>
    </div>
</div>
<!--end delete part2-->
</div>
</div>

<!-- Matter ends -->

</div>

<!-- Mainbar ends -->
<div class="clearfix"></div>